package com.smartwebee.android.blespp.hospital;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import java.util.List;

/**
 * Created by steward on 2018/6/27.
 */

public abstract class HospitalBaseAdapter<T> extends BaseAdapter {
    protected Context context;
    protected LayoutInflater inflater;
    protected List<T> datas;
    protected HospitalBaseAdapter(Context context, List<T> datas) {
        this.context = context;
        this.datas = datas;
        inflater = LayoutInflater.from(context);
    }
    @Override
    public int getCount() {
        return datas.size();
    }

    @Override
    public T getItem(int position) {
        return datas.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        return initView(position, convertView, parent);
    }
    protected abstract View initView(int position, View convertView, ViewGroup parent);
    public void addItems(List<T> datas) {
        this.datas.addAll(datas);
        notifyDataSetChanged();
    }
    public void setItems(List<T> datas) {
        this.datas.clear();
        this.datas.addAll(datas);
        notifyDataSetChanged();
    }

    public void addItem(T data) {
        this.datas.add(data);
        notifyDataSetChanged();
    }
    public void clear() {
        this.datas.clear();
        notifyDataSetChanged();
    }
}
